package com.syp.envops.service.impl;

import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.syp.envops.dao.UserMapper;
import com.syp.envops.domain.pojo.UserSchema;
import com.syp.envops.domain.vo.UserVo;
import com.syp.envops.service.UserServiceI;
import com.syp.envops.util.SessionInfo;

@Service("userService")
public class UserServiceImpl implements UserServiceI {

	@Autowired
	private UserMapper userMapper;

	@Override
	public void dsignup(UserVo user) {
		UserSchema userSchema = new UserSchema();
		userSchema.setUsername(user.getUsername());
		userSchema.setPassword(user.getPassword());
		userSchema.setLastUpdate(Calendar.getInstance().getTime());
		userSchema.setCreateTime(Calendar.getInstance().getTime());

		this.userMapper.insert(userSchema);
	}

	@Override
	public SessionInfo dsignin(UserVo user) {
		SessionInfo sessionInfo = null;
		UserSchema userSchema = this.userMapper.signin(user.getUsername(), user.getPassword());
		if (userSchema != null) {
			sessionInfo = new SessionInfo();
			sessionInfo.setUsername(userSchema.getUsername());
			sessionInfo.setPassword(userSchema.getPassword());
			sessionInfo.setAvatar(userSchema.getAvatar());
			sessionInfo.setEmail(userSchema.getEmail());
			sessionInfo.setMobile(userSchema.getMobile());
			sessionInfo.setSex(userSchema.getSex());
			sessionInfo.setSiginIp(user.getSigninIp());
			sessionInfo.setLastUpdate(userSchema.getLastUpdate());
			sessionInfo.setCreateTime(userSchema.getCreateTime());
		}

		return sessionInfo;
	}

}
